class Solution {
    void dfs(TreeNode* root,vector<int>& ans)
    {
        if(root==nullptr) return;
        dfs(root->left,ans);
        ans.push_back(root->val);
        dfs(root->right,ans);

    }
public:
    vector<int> inorderTraversal(TreeNode* root) {
        vector<int> ans;
        if(root==nullptr) return ans;
        dfs(root,ans);
        return ans;

    }
};


// class Solution {
//     vector<int> ans;
// public:
//     vector<int> inorderTraversal(TreeNode* root) {
//         if(root==nullptr) return{};

//         inorderTraversal(root->left);
//         ans.push_back(root->val);
//         inorderTraversal(root->right);

//         return ans;
//     }
// };